package com.fwtai.api;

import com.fwtai.bean.PageFormData;
import com.fwtai.datasource.DaoHandle;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;

/**
 * 用户收货地址访问数据库
 * @作者 李宇鹏
 * @版本 v1.0
 * @创建时间 2023-06-28 11:07:53
 * @QQ号码 444141300
 * @Email service@fwtai.com
 * @官网 <url>http://www.fwtai.com</url>
*/
@Repository
public class ApiUserAddressDao {

  private final DaoHandle dao;

  public ApiUserAddressDao(final DaoHandle dao){
    this.dao = dao;
  }

  public int add(final PageFormData formData){
    final Integer defaults = formData.getInteger("defaults");
    if(defaults == 1){
      dao.execute("api_user_address.editDefaults",formData);
    }
    return dao.execute("api_user_address.add",formData);
  }

  public int edit(final PageFormData formData){
    final Integer defaults = formData.getInteger("defaults");
    if(defaults == 1){
      dao.execute("api_user_address.editDefaults",formData);
    }
    return dao.execute("api_user_address.edit",formData);
  }

  public Long queryExistById(final long kid){
    return dao.queryForLong("api_user_address.queryExistById",kid);
  }

  public HashMap<String,Object> queryById(final long kid){
    return dao.queryForHashMap("api_user_address.queryById",kid);
  }

  public int delById(final long kid){
    return dao.execute("api_user_address.deletedById",kid);
  }

  public int delByKeys(final long[] list){
    return dao.execute("api_user_address.deletedByKeys",list);
  }

  public List<HashMap<String,Object>> getListData(final PageFormData formData){
    return dao.queryForListHashMap("api_user_address.listData",formData);
  }

  public HashMap<String,Object> getDefaultAddress(final long user_id){
    return dao.queryForHashMap("api_user_address.getDefaultAddress",user_id);
  }
}